import {request} from '@/utils/request'
import type { HbtOperationRate, HbtOperationRateQuery, HbtOperationRateCreate, HbtOperationRateUpdate, HbtOperationRateStatus } from '@/types/logistics/manufacturing/master/operationRate'
import type { HbtPagedResult, HbtApiResponse, HbtSelectOption } from '@/types/common'

/**
 * 获取稼动率分页列表
 */
export function getOperationRateList(params: HbtOperationRateQuery) {
  return request<HbtPagedResult<HbtOperationRate>>({
    url: '/api/HbtOperationRate/list',
    method: 'get',
    params
  })
}

/**
 * 获取稼动率详情
 */
export function getOperationRateById(operationRateId: number | bigint) {
  return request<HbtOperationRate>({
    url: `/api/HbtOperationRate/${operationRateId}`,
    method: 'get'
  })
}

/**
 * 创建稼动率
 */
export function createOperationRate(data: HbtOperationRateCreate) {
  return request<number>({
    url: '/api/HbtOperationRate',
    method: 'post',
    data
  })
}

/**
 * 更新稼动率
 */
export function updateOperationRate(data: HbtOperationRateUpdate) {
  return request<boolean>({
    url: '/api/HbtOperationRate',
    method: 'put',
    data
  })
}

/**
 * 删除稼动率
 */
export function deleteOperationRate(operationRateId: number | bigint) {
  return request<boolean>({
    url: `/api/HbtOperationRate/${operationRateId}`,
    method: 'delete'
  })
}

/**
 * 批量删除稼动率
 */
export function batchDeleteOperationRate(operationRateIds: (number | bigint)[]) {
  return request<boolean>({
    url: '/api/HbtOperationRate/batch',
    method: 'delete',
    data: operationRateIds
  })
}

/**
 * 更新稼动率状态
 */
export function updateOperationRateStatus(data: HbtOperationRateStatus) {
  return request<boolean>({
    url: '/api/HbtOperationRate/status',
    method: 'put',
    data
  })
}

/**
 * 获取稼动率选项列表
 */
export function getOperationRateOptions() {
  return request<HbtSelectOption[]>({
    url: '/api/HbtOperationRate/options',
    method: 'get'
  })
}

/**
 * 导入稼动率数据
 */
export function importOperationRate(file: File) {
  const formData = new FormData()
  formData.append('file', file)
  
  return request<{ success: number; fail: number }>({
    url: '/api/HbtOperationRate/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 导出稼动率数据
 */
export function exportOperationRate(params: HbtOperationRateQuery) {
  return request({
    url: '/api/HbtOperationRate/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

/**
 * 获取稼动率导入模板
 */
export function getOperationRateTemplate() {
  return request({
    url: '/api/HbtOperationRate/template',
    method: 'get',
    responseType: 'blob'
  })
}
